package com.zhangzhan.blog_api.controller;


import com.zhangzhan.base.common_model.result.ResponseResult;
import com.zhangzhan.blog_model.vos.ArticleDetailVo;
import com.zhangzhan.blog_model.vos.HotArticleVo;
import com.zhangzhan.blog_model.vos.PageVo;
import com.zhangzhan.blog_service.service.ArticleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author zhangzhan
 * @since 2024-01-30
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 查询热文章
     * @return
     */
    @RequestMapping(value = "/hotArticleList", method = RequestMethod.GET)
    public ResponseResult<List<HotArticleVo>> hotArticleList() {
        return articleService.hotArticleList();
    }


    @ApiOperation(value = "分页查询文章列表")
    @RequestMapping(value = "/articleList", method = RequestMethod.GET)
    public ResponseResult<List<PageVo>> articleList(@RequestParam("pageNum") Long pageNum,
                                                    @RequestParam("pageSize") Long pageSize,
                                                    @RequestParam("categoryId") Long categoryId) {
        return articleService.articleList(pageNum,pageSize,categoryId);
    }


    @ApiOperation(value = "文章详情接口")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ResponseResult<ArticleDetailVo> articleDetail(@PathVariable("id") Long id) {
        return articleService.articleDetail(id);
    }
}

